<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page
	import="com.onlineMIS.common.Common_util,java.util.Date,java.text.SimpleDateFormat"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>朴与素连锁店管理信息系统</title>
<%@ include file="../../common/Style.jsp"%>
<script>

var baseurl = "<%=request.getContextPath()%>";
$(document).ready(function(){
	parent.$.messager.progress('close'); 
	$.messager.progress({
		title : '提示',
		text : '数据处理中，请稍后....'
	});
	
	var params= $.serializeObject($('#preGenReportForm'));
	$('#dataGrid').treegrid({
		url : 'headQReportJSON!getTabletStatistics',
		idField: 'id',
		queryParams: params,
		treeField : 'name',
		rownumbers: true,
		lines : true,

		onLoadSuccess : function(row, param){
			$.messager.progress('close'); 
		},
		onBeforeExpand : function(node) {
			$("#parentId").val( node.parentId);
		    $("#yearId").val( node.yearId);
			$("#quarterId").val( node.quarterId);
			$("#brandId").val( node.brandId);
			$("#categoryLevelId").val(node.categoryLevelId);
			$("#categoryId").val(node.categoryId);
			$("#pbId").val(node.pbId);
			var params = $('#preGenReportForm').serialize();
			$('#dataGrid').treegrid('options').url = 'headQReportJSON!getTabletStatistics?' + params;
		},	
		rowStyler: function(row){
            var style = "";
            if (row.notManuf == true)
            	style = "background-color:#FF9999;";
			return style;
		},
		frozenColumns :[[					
						{field:'name', width:280,title:' <s:property value="formBean.searchStartTime"/>到 <s:property value="formBean.searchEndTime"/>',
							formatter: function (value, row, index){
								if (row.state == 'open' && row.chainId != -1) {
									var str = '';
								    str += $.formatString('<a href="#" onclick="traceInventory(\'{0}\');">{1}</a>', row.barcode, row.name);
								    return str;
								} else 
									return row.name;
							}}
							
							]],
		columns : [ [
				{field:'img',width:60,title:'图片',
					formatter : function(value, row, index) {
						if(row.img != ""){
							var str = '';
							  str += $.formatString('<a href="#" onclick="viewImg({0});">{1}</a>', row.barcode,row.img);
							return str;
						}else {
							return row.img;
						}
						
					}},
					{field:'quantity', width:65,title:'选货数量',
						formatter : function(value, row, index) {
							if (row.barcode != "")
							   return $.formatString('<a href="#" onclick="tracePeihuo({0},1);">{1}</a>', row.barcode,row.quantity);
							else 
							   return row.quantity;
						}},
					{field:'quantityPei', width:65,title:'配货数量',
					    formatter : function(value, row, index) {
						    if (row.barcode != "")
						   		return $.formatString('<a href="#" onclick="tracePeihuo({0},2);">{1}</a>', row.barcode,row.quantityPei);
						    else 
							   return row.quantityPei;						
					}},
					{field:'noQuantityPei', width:65,title:'未配数量',
				        formatter : function(value, row, index) {
						if (row.barcode != "")
						   return $.formatString('<a href="#" onclick="tracePeihuo({0},3);">{1}</a>', row.barcode,row.noQuantityPei);
						else 
							   return row.noQuantityPei;
					}},

					{field:'progress', width:100,title:'配货率',formatter: function (v, r, i) {	
						var htmlstr = "";
						if(v <= 60){
							 htmlstr = '<div class="easyui-progressbar progressbar easyui-fluid" style="width: 100%; height: 20px;">'
								  + '<div class="progressbar-value" style="width: '+v+'%; height: 20px; line-height: 20px; background-color:#FFC0CB;"> '
								  + '<div class="progressbar-text" style="width: ' + v+'%'+ '; height: 20px; line-height: 20px;background-color:#FFC0CB;">' + v+ '%</div>'
								  + '</div>'
								  + '</div>';
								  return htmlstr;	
						}else if(v<100 && v>60){
							 htmlstr = '<div class="easyui-progressbar progressbar easyui-fluid" style="width: 100%; height: 20px;">'
								  + '<div class="progressbar-value" style="width: '+v+'%; height: 20px; line-height: 20px; background-color:#FFDAB9;"> '
								  + '<div class="progressbar-text" style="width: ' + v+'%'+ '; height: 20px; line-height: 20px;background-color:#FFDAB9;">' + v+ '%</div>'
								  + '</div>'
								  + '</div>';
								  return htmlstr;	
						}else if(v==100){
							htmlstr = '<div class="easyui-progressbar progressbar easyui-fluid" style="width: 100%; height: 20px;">'
								  + '<div class="progressbar-value" style="width: '+v+'%; height: 20px; line-height: 20px; background-color:#C1FFC1;"> '
								  + '<div class="progressbar-text" style="width: ' + v+'%'+ '; height: 20px; line-height: 20px;background-color:#C1FFC1;">' + v+ '%</div>'
								  + '</div>'
								  + '</div>';
								  return htmlstr;	
						}					 
					}},
					  {field:'inventory', width:65,title:'当前库存',
				        formatter : function(value, row, index) {
						if (row.barcode != "")
						   return row.inventory;
					}}
					
			     ]],
		toolbar : '#toolbar',
	});
});

/**
 * 刷新
 */
function refresh(){
	$("#parentId").val( 0);
    $("#yearId").val( 0);
	$("#quarterId").val( 0);
	$("#brandId").val( 0);
	$("#categoryLevelId").val(0);
	$("#categoryId").val(0);
    document.preGenReportForm.action="headqReportJSP!preTabletDistributionDetails";
    document.preGenReportForm.submit();
}
/**
 * 返回
 */
function back(){
    document.preGenReportForm.action="headqReportJSP!preTabletDistribution";
    document.preGenReportForm.submit();
}
/**
 * 下载
 */
function exportFile(){
	
	var node = $('#dataGrid').treegrid('getSelected');

	if (node == null){
		$.messager.alert('错误', '请先选中一行再继续操作', 'error');
	} else {

		$("#chainId").val( node.chainId);
	    $("#yearId").val( node.yearId);
		$("#quarterId").val( node.quarterId);
		$("#brandId").val( node.brandId);
		$("#categoryLevelId").val(node.categoryLevelId);
		$("#categoryId").val(node.categoryId);
        document.preGenReportForm.action="headqReportJSP!downloadTabletExcelReport";
        document.preGenReportForm.submit();
	}
}


/**
 * 货品销售记录
 */
function traceInventory(barcode){
	var custId = $("#custId").val();
	var startDate = $("#startDate").val();
	var endDate = $("#endDate").val();
	var params = "formBean.barcode="+ barcode +"&formBean.cust.id="+custId +"&formBean.searchStartTime="+startDate +"&formBean.searchEndTime="+endDate;
			$.modalDialog({
				title : barcode + " 货品信息跟踪",
				width : 620,
				height : 320,
				modal : false,
				draggable:true,
				href : 'headqReportJSP!selectSalesRecords?' + params,
		});		
	
}

/**
 * 货品配货记录
 */
function tracePeihuo(barcode, reportType){
	var custId = $("#custId").val();
	var startDate = $("#startDate").val();
	var endDate = $("#endDate").val();
	var params = "formBean.reportType="+ reportType +"&formBean.barcode="+ barcode +"&formBean.cust.id="+custId +"&formBean.searchStartTime="+startDate +"&formBean.searchEndTime="+endDate;
			$.modalDialog({
				title : barcode + " 配货信息跟踪",
				width : 720,
				height : 320,
				modal : false,
				draggable:true,
				href : 'headqReportJSP!getPeiHuoTraceRecords?' + params,
		});		

}

/**\
 * 取消标注产品停产
 */
function disableStopManuf(){
	var node = $('#dataGrid').treegrid('getSelected');

	if (node == null || node.pbId ==0){
		$.messager.alert('错误', '请先选中一行产品再继续操作', 'error');
	} else {
		var params = "formBean.productBarcode.id=" + node.pbId + "&formBean.productBarcode.status=1"
		   $.post("<%=request.getContextPath()%>/action/productJSONAction!changeBarcodeStatus",params, stopManufBKProcess,"json");
	}
}

/**\
 * 标注产品停产
 */
function enableStopManuf(){
	var node = $('#dataGrid').treegrid('getSelected');

	if (node == null || node.pbId ==0){
		$.messager.alert('错误', '请先选中一行产品再继续操作', 'error');
	} else {
		var params = "formBean.productBarcode.id=" + node.pbId + "&formBean.productBarcode.status=3";
		   $.post("<%=request.getContextPath()%>/action/productJSONAction!changeBarcodeStatus",params, stopManufBKProcess,"json");
	}
}
function stopManufBKProcess(data){
	
	var response = data;
	var returnCode = response.returnCode;
	var returnMsg = response.message;
	if (returnCode == SUCCESS){		   
		$.messager.alert('', returnMsg, 'info');

	} else {
        $.messager.alert('失败警告', returnMsg, 'error');
    }
}

</script>
</head>
<body>
	<div class="easyui-layout" data-options="fit : true,border : false">
		<div data-options="region:'north',border:false" style="height: fit">
			<s:form id="preGenReportForm" name="preGenReportForm" action=""
				theme="simple" method="POST">
				<s:hidden name="formBean.parentId" id="parentId" />
				<s:hidden name="formBean.searchStartTime" id="startDate" />
				<s:hidden name="formBean.searchEndTime" id="endDate" />
				<s:hidden name="formBean.cust.id" id="custId" />
				<s:hidden name="formBean.barcode" id="barcode"/>
				<s:hidden name="formBean.reportType" id="reportType"/>
				<s:hidden name="formBean.belongTo" id="belongTo"/>
				<input type="hidden" name="formBean.year.year_ID" id="yearId"
					value="0" />
				<input type="hidden" name="formBean.quarter.quarter_ID"
					id="quarterId" value="0" />
				<input type="hidden" name="formBean.brand.brand_ID" id="brandId"
					value="0" />
				<input type="hidden" name="formBean.categoryLevel.category_ID" id="categoryLevelId" value="0"/>
            	<input type="hidden"  name="formBean.category.category_ID" id="categoryId" value="0"/>
            	<s:hidden name="formBean.rptTypeId" id="rptTypeId"/>
			</s:form>
		</div>
		<div data-options="region:'center',border:false">
			<table id="dataGrid">
			</table>
			<div id="toolbar" style="display: none;">
				<a onclick="back();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:false,iconCls:'icon-back'">退回上页</a> <a
					onclick="refresh();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:false,iconCls:'icon-reload'">刷新</a> <a
					onclick="exportFile();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:false,iconCls:'icon-print'">导出报表</a><a
					onclick="enableStopManuf();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:false,iconCls:'icon-edit'">标注条码停产</a> <a
					onclick="disableStopManuf();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:false,iconCls:'icon-redo'">取消标注停产</a> 
			</div>
		</div>
	</div>
</body>
</html>